package cn.msi.customer.service;

import java.util.Date;

import cn.common.util.GeneralUtils;
import cn.msi.customer.domain.ChkOrg;
import cn.msi.customer.mapper.ChkOrgMapper;

/**
 * 被客户调研组织机构业务处理类
 * 
 * @author Administrator
 * 
 */
public class ChkOrgService {

	private ChkOrgMapper chkOrgMapper;

	/**
	 * 根据选择的客户查询该客户的被调组织机构列表
	 * 
	 * @param chkOrg
	 * @return
	 */
	public String searchChkOrg(ChkOrg chkOrg) {
		return GeneralUtils.easyUI(chkOrgMapper.count(chkOrg), chkOrgMapper.selectList(chkOrg));
	}

	/**
	 * 根据ID查找被调组织机构信息
	 * 
	 * @param chkOrgId
	 * @return
	 */
	public ChkOrg findChkOrg(ChkOrg chkOrg) {
		if (chkOrg != null && chkOrg.getChkOrgId() != null) {
			chkOrg = chkOrgMapper.selectById(chkOrg.getChkOrgId());
		}
		return chkOrg;
	}

	/**
	 * 编辑客户的组织机构信息
	 * 
	 * @param chkOrg
	 */
	public void redactChkOrg(ChkOrg chkOrg) {
		if(chkOrg != null && chkOrg.getChkOrgId() != null) {
			chkOrgMapper.update(chkOrg);
		} else {
			chkOrg.setCreateTime(new Date());
			chkOrgMapper.insert(chkOrg);
		}
	}
	
	/**
	 * 删除客户组织机构
	 * @param chkOrg
	 */
	public void deleteChkOrg(ChkOrg chkOrg) {
		chkOrgMapper.deleteById(chkOrg.getChkOrgId());
	}

	public void setChkOrgMapper(ChkOrgMapper chkOrgMapper) {
		this.chkOrgMapper = chkOrgMapper;
	}
}
